using System;
using System.Windows.Forms;
using CombatTracker.Creatures;

namespace CombatTracker.Controls
{
  public partial class AddPlayerDialog : Form
  {
    private Creature _newPlayer;

    public Creature NewPlayer
    {
      get { return _newPlayer; }
    }

    public AddPlayerDialog()
    {
      InitializeComponent();
      _newPlayer = null;
    }

    public new DialogResult ShowDialog()
    {
      txtName.Text = String.Empty;
      txtName.Select();
      txtInitiativeBonus.Text = "0";

      return base.ShowDialog();
    }

    private void btnAdd_Click(object sender, EventArgs e)
    {
      int bonus = 0;
      if (txtName.Text != String.Empty && int.TryParse(txtInitiativeBonus.Text, out bonus))
      {
        _newPlayer =
          CreatureFactory.CreateCreature(new CreatureParameters(txtName.Text, CreatureType.Player));
        _newPlayer.InitiativeBonus = bonus;
        DialogResult = DialogResult.OK;
        Close();
      }
      else
      {
        MessageBox.Show("Players require a name and a numeric initiative bonus.", "Entry Error", MessageBoxButtons.OK,
                        MessageBoxIcon.Exclamation);
      }
    }
  }
}